package com.Txunda.fxw.ui.adapter;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.Txunda.fxw.R;
import com.Txunda.fxw.ui.activity.other.DetailAty;
import com.Txunda.fxw.ui.callback.MyItemClickListener;
import com.Txunda.fxw.ui.adapter.model.BottomDetailViewHolder;
import com.bumptech.glide.Glide;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;
import java.util.Map;

public class BottomLawAdapter2 extends RecyclerView.Adapter<BottomDetailViewHolder> {

    private List<Map<String, String>> list;

    private Activity act;

    public List<Map<String, String>> getList() {
        return list;
    }

    public void setList(List<Map<String, String>> list) {
        this.list = list;
    }

    public BottomLawAdapter2(Activity act) {
        this.act = act;
    }

    @Override
    public int getItemCount() {
        int ret = 0;
        if (list != null) {
            ret = list.size();
        }
        return ret;
    }

    @Override
    public void onBindViewHolder(@NonNull BottomDetailViewHolder holder, final int position) {
        final String name = list.get(position).get("name");
        if (name.equals("")) {
            holder.getBottom_detail_img().setVisibility(View.INVISIBLE);
            holder.getBottom_detail_title().setVisibility(View.INVISIBLE);
        } else {
            holder.getBottom_detail_img().setVisibility(View.VISIBLE);
            holder.getBottom_detail_title().setVisibility(View.VISIBLE);
            Glide.with(act).load(list.get(position).get("cover_pic")).into(holder.getBottom_detail_img());
            holder.getBottom_detail_title().setText(list.get(position).get("name"));
        }
        final String com_id = list.get(position).get("com_id"); // 商家id
        final String class_id = list.get(position).get("class_id");

        holder.itemView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (name.equals("")) {
                    return;
                }
                // 普通商家
                Intent intent = new Intent(act, DetailAty.class);
                Bundle bundle = new Bundle();
                bundle.putString("com_id", com_id);
                bundle.putString("class_id", class_id);
                bundle.putString("name", name);
                bundle.putString("district_name", "");
                intent.putExtras(bundle);
                act.startActivity(intent);
                act.finish();
            }
        });
    }

    @NonNull
    @Override
    public BottomDetailViewHolder onCreateViewHolder(@NonNull ViewGroup arg0, int arg1) {
        View view = LayoutInflater.from(act).inflate(R.layout.item_bottom_detail2, arg0, false);
        return new BottomDetailViewHolder(view);
    }

}
